﻿<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="ListNewsUC.ascx.cs"
    Inherits="VCN.home.UC.ListNewsUC" %>
<div id="listnewsUc">
    <%
        int m_i_pageNum = 1;
        int m_i_pageNews = 5;
        // số tin, giúp ta đánh số các trang
        int m_i_allNews = 0;
        VCN.App.DataAccessLayer.NewsDAO m_news_dao = new VCN.App.DataAccessLayer.NewsDAO();

        if (Request.QueryString["Page"] != null)
            int.TryParse(Request.QueryString["Page"].ToString(), out m_i_pageNum);


        System.Collections.Generic.List<VCN.App.DataTransferObjects.News> m_lstnew_obj = m_news_dao.SelectInPage(m_i_pageNum, m_i_pageNews);
        m_i_allNews = m_news_dao.SelectNewsCount();
        if (m_lstnew_obj != null && m_lstnew_obj.Count > 0)
        {
            foreach (VCN.App.DataTransferObjects.News item in m_lstnew_obj)
            {
    %>
    <div class="item">
        <%
            Response.Write(string.Format("<div class='meta'>{0} {1:00}:{2:00}:{3:00} | View: {4:0,0}</div>", item.CreatedDate.ToString("dd/MM/yyyy"), item.CreatedDate.Hour, item.CreatedDate.Minute, item.CreatedDate.Second, item.ViewCount.ToString()));
            Response.Write(string.Format("<div class='img'><a href='./News.aspx?NId={0}' title='{1}'><img src='Images/News/{2}' alt='{3}'/><span class='icon'></span></a></div>", item.Id, item.Title, item.NewsImage, item.Title)); 
                %>
        <div class="postcontent">
            <div class="subtitle">
            </div>
            <%Response.Write(string.Format("<div class='title'><a href='./News.aspx?NId={0}'>{1}</a></div><div class='sapo'>{2}</div>", item.Id, item.Title, item.ShortContent)); %>
        </div>
        <ul>
        </ul>
    </div>
    <%
        }
        }
        
    %>
    <div class="pagercontainer">
        <%int m_i_pageCount = (m_i_allNews - 1) / m_i_pageNews + 1;
          string v_str_html = "";
          if (m_i_pageCount == 1)
          {
          }
          else
          {
              if (m_i_pageNum > 1)
              {
                  v_str_html += string.Format("<a href='./ListNews.aspx?Page={0}'>« Trước</a>", m_i_pageNum - 1);
              }

              for (int i = m_i_pageNum - 2; i < m_i_pageNum + 3; i++)
              {
                  if (i > 0 && i <= m_i_pageCount)
                  {
                      if (i != m_i_pageNum)
                          v_str_html += string.Format("<a href='./ListNews.aspx?Page={0}'>{1}</a>", i, i);
                      else
                          v_str_html += string.Format("<div class='currentpage'>{0}</div>", i);
                  }
              }

              if (m_i_pageNum < m_i_pageCount)
              {
                  v_str_html += string.Format("<a href='./ListNews.aspx?Page={0}'>Sau »</a>", m_i_pageNum + 1);

              }


              Response.Write(v_str_html);
          } %>
    </div>
</div>
